package com.xindong.paking.controller;


import com.xindong.paking.dtos.TbSpaceListParams;
import com.xindong.paking.entity.TbSpace;
import com.xindong.paking.service.TbSpaceService;
import com.xindong.paking.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  停车位前端控制器
 * </p>
 *
 * @author wenbo
 * @since 2023-01-08
 */
@Api(tags = "停车位模块")
@RestController
@RequestMapping("/space")
public class TbSpaceController {

    @Autowired
    private TbSpaceService tbSpaceService;

    /**
     * 新增停车位
     * @param tbSpace
     * @return
     */
    @ApiOperation("新增停车位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parking_id", value = "停车场id"),
            @ApiImplicitParam(name = "is_charging_pile", value = "是否有充电桩（0：没有，1：有）")
    })
    @PostMapping("add")
    public Result add(@RequestBody TbSpace tbSpace) {
        return tbSpaceService.add(tbSpace);
    }

    /**
     * 删除停车位
     * @param id 停车位id
     * @return
     */
    @ApiOperation("删除停车位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "停车位id", required = true)
    })
    @DeleteMapping("delete")
    public Result delete(@RequestParam("id") Integer id) {
        return tbSpaceService.delete(id);
    }

    /**
     * 更新停车位
     * @param tbSpace
     * @return
     */
    @ApiOperation("更新停车位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "停车位id", required = true),
            @ApiImplicitParam(name = "start_time", value = "停车位开始使用时间"),
            @ApiImplicitParam(name = "license_plate_number", value = "车牌号"),
            @ApiImplicitParam(name = "is_charging_pile", value = "是否有充电桩（0：没有，1：有）"),
            @ApiImplicitParam(name = "is_free", value = "是否空闲（0：空闲，1：有车辆）"),
            @ApiImplicitParam(name = "parking_id", value = "停车场id")

    })
    @PutMapping("update")
    public Result update(@RequestBody TbSpace tbSpace) {
        return tbSpaceService.update(tbSpace);
    }

    /**
     * 分页查询
     * @param params
     * @return
     */
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true),
            @ApiImplicitParam(name = "id", value = "停车位id"),
            @ApiImplicitParam(name = "licensePlateNumber", value = "车牌号"),
            @ApiImplicitParam(name = "isChargingPile", value = "是否有充电桩（0：没有，1：有）"),
            @ApiImplicitParam(name = "isFree", value = "是否空闲（0：空闲，1：有车辆）"),
            @ApiImplicitParam(name = "parkingId", value = "停车场id")

    })
    @GetMapping("list")
    public Result list(TbSpaceListParams params) {
        return tbSpaceService.list(params);
    }

    /**
     * 入库
     * @param tbSpace
     * @return
     */
    @ApiOperation("入库")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "停车位id", required = true),
            @ApiImplicitParam(name = "licensePlateNumber", value = "车牌号", required = true)
    })
    @PutMapping("warehousing")
    public Result warehousing(@RequestBody TbSpace tbSpace) {
        return tbSpaceService.warehousing(tbSpace);
    }

    /**
     * 出库
     * @param tbSpace
     * @return
     */
    @ApiOperation("出库")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "停车位id", required = true)
    })
    @PutMapping("issue")
    public Result issue(@RequestBody TbSpace tbSpace) {
        return tbSpaceService.issue(tbSpace);
    }

    /**
     * 通过id查找
     * @param id
     * @return
     */
    @ApiOperation("通过id查找")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "停车位id", required = true)
    })
    @GetMapping("selectById")
    public Result selectById(Integer id) {
        return tbSpaceService.selectById(id);
    }

    @ApiOperation("根据停车场id获取停车位使用率")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parkingId", value = "停车场id", required = false)
    })
    @GetMapping("utilizationRate")
    public Result utilizationRate(Integer parkingId) {
        return tbSpaceService.utilizationRate(parkingId);
    }

}

